package com.koron.css2.newProjectCenter.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.css2.ServerInterface;
import com.koron.css2.newProjectCenter.bean.PjProcessNodeTimePostponeBean;
import com.koron.css2.newProjectCenter.bean.query.PjProcessNodeTimePostponeQueryBean;
import com.koron.css2.newProjectCenter.mapper.PjProcessNodeTimePostponeMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.apache.commons.lang3.StringUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;
import java.util.Objects;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: ；lwc
 * @Date: 2023/11/15/9:39
 * @Description:
 */
public class PjNodeListInfo implements ServerInterface {
    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        try {
            PjProcessNodeTimePostponeQueryBean pjProcessNodeTimePostponeBean = JsonUtils.objectToPojo(req.getData(), PjProcessNodeTimePostponeQueryBean.class);
            Objects.requireNonNull(pjProcessNodeTimePostponeBean,"参数不能为空");
            if (StringUtils.isBlank(pjProcessNodeTimePostponeBean.getBillId())){
                throw new RuntimeException("缺少参数");
            }

            PageHelper.startPage(pjProcessNodeTimePostponeBean.getPage(), pjProcessNodeTimePostponeBean.getPageCount());
            PjProcessNodeTimePostponeMapper mapper = factory.getMapper(PjProcessNodeTimePostponeMapper.class);
            List<PjProcessNodeTimePostponeBean> listByPjId = mapper.getListByPjId(pjProcessNodeTimePostponeBean.getBillId());

            MessageBean<PageInfo> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "查询成功", PageInfo.class);
            info.setData(new PageInfo<>(listByPjId));
            return info;
        } catch (Exception e) {
            factory.close(false);
            logger.error("列表查询失败" + e.getMessage(), e);
            e.printStackTrace();
            return MessageBean.create(Constant.MESSAGE_INT_FAIL, "查询失败:"+e.getMessage(), null);
        }

    }
}
